# Create your views here.
from django.http import HttpResponse,HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render,render_to_response
# from .models import Products
from .forms import ContactUsForm
from .models import ContactUs
def contact(request):
	# form = ContactUsForm(request.POST or None)
	# if form.is_valid():
	# 	this_form = form.save(commit=False)
	# 	this_form.save()
	# return render_to_response('contact/form.html',locals(),context_instance=RequestContext(request))
	#return render(request,'contact/form.html',{'form':form})
	if request.method == 'POST':
		form = ContactUsForm(request.POST)
		if form.is_valid():
			email = request.POST['email']
			name = request.POST['name']
			message = request.POST['message']
			newmessage=ContactUs(email=email,message=message,name=name)
			newmessage.save()
			return HttpResponseRedirect('/')
	else:
		form = ContactUsForm()
	return render(request, 'contact/form.html', {'form': form})